package com.pkk.penguin.frame.know.java.Javacoreknowledge.thread.threadlief;

import java.util.concurrent.atomic.AtomicLong;
import org.junit.Test;

/**
 * @description: 线程声明周期探索
 * @author: peikunkun
 * @create: 2019-12-25 15:50
 **/
public class ThreadLiefSimple extends Thread {

  private volatile AtomicLong count = new AtomicLong(0);

  /**
   * If this thread was constructed using a separate
   * <code>Runnable</code> run object, then that
   * <code>Runnable</code> object's <code>run</code> method is called;
   * otherwise, this method does nothing and returns.
   * <p>
   * Subclasses of <code>Thread</code> should override this method.
   *
   * @see #start()
   * @see #stop()
   */
  @Override
  public void run() {
    while (!isInterrupted()) {
      try {
        final long l = count.addAndGet(1);
        System.out.println("~~~~:" + l);
        Thread.sleep(1L);
      } catch (InterruptedException e) {
        e.printStackTrace();
        break;
      }
    }
  }

  @Test
  public void Administrator_12_20191225155030() {
    System.out.println("欢迎使用单元测试方法【Administrator_12()_20191225155030】");
    System.out.println("此方法测试描述：【】");
    final ThreadLiefSimple threadLiefSimple = new ThreadLiefSimple();
    //设置为守护线程
    threadLiefSimple.setDaemon(true);
    threadLiefSimple.start();
  }

}
